// 链表的逆序
function revertlist(head) {
    if (!haed || !head.next) return head;
    let next = head.next;
    let headrevert = revertlist(head.next);
    head.next = null;
    next.next = head;
    return headrevert
}

// 链表逆序 n-m
function revertlist(head, m, n) {
    let dumy = new ListNode(0);
    dumy.next = head;

    let temHead = dumy;
    for (let i = 0; i < m - 1; i++) {
        temHead = temHead.next;
    }

    var pre = null;
    var current = temHead.next;

    for (let j = 0; j < n - m; i++) {
        var next = current.next;
        temHead.next = pre;
        pre = current;
        current = next
    }

    temHead.next.next = current;
    temHead.next = pre
    return dumy.next
}

// 判断链表求焦点
function getIntersectionNode(headA, headB) {
    while (headA) {
        headA.tag = true;
        headA = headA.next;
    }
    while (headB) {
        if (headB.tag) return true
        headB = headB.next;
    }
    return false
}

// 判断链表是否有环
function hasCycle(head) {
    while (head) {
        if (head.tag) return true;
        head.tag = true;
        head = head.next
    }
    return false
}

// 链表的划分
function parition(head, x) {
    let node = new ListNode(0);
    node.next = head;
    let pre = node;
    let cur = node.next;
    let arr = [];
    let ishas = 0;
    while (cur) {
        if (cur.val == x || cur.val > x) {
            pre.next = cur.next;
            cur.next = null;
            arr.push(cur)
            ishas = 1
        }
        if (ishas) {
            cur = pre.next;
            ishas = 0
        } else {
            pre = pre.next;
            cur = cur.next;
        }
    }

    while (arr.length) {
        pre.next = arr.shift();
        pre = pre.next
    }
    return node.next
}


// 两个链表的归并
function mergeTwoList(l1, l2) {
    if (l1 == null) {
        return l2
    }
    if (l2 == null) {
        return l1
    }
    if (l1.val < l2.val) {
        l1.next = mergeTwoList(l1.next, l2)
        return l1
    } else {
        l2.next = mergeTwoList(l1,l2.next)
        return l2
    }

}